package com.jy.wms.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jy.wms.common.annotions.BaseServiceDescribe;
import com.jy.wms.common.base.BaseService;
import com.jy.wms.common.base.ServiceException;
import com.jy.wms.common.base.SucessException;
import com.jy.wms.dao.WmsCustomerFileConsigneeMapper;
import com.jy.wms.pojo.WmsCustomerFileConsignee;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @ClassName: WmsCustomerFileConsigneeService.java
* @Description: TODO(这里用一句话描述这个类的作用)
* @Author Liyi
* @Date Thu Oct 12 11:26:43 CST 2017
*/

@Service
public class WmsCustomerFileConsigneeService extends BaseService<WmsCustomerFileConsigneeMapper,WmsCustomerFileConsignee> {

 /**
 * 插入一条记录
 * @param entity 实体对象
 * @return int
 */
 @BaseServiceDescribe(moduleName = "客户档案收货人详细信息",btnName = "新增客户档案收货人详细信息")
public Integer baseInsert(WmsCustomerFileConsignee entity)throws SucessException,ServiceException {
     Integer addCount = dao.baseInsert( entity );
     if(addCount>0){
         throw new SucessException("新增客户档案收货人详细信息成功");
     }else{
         throw new ServiceException("新增客户档案收货人详细信息");
     }
 }

/**
* 插入一条记录（匹配有值的字段）
* @param entity 实体对象
* @return int
*/
public Integer baseInsertSelective(WmsCustomerFileConsignee entity){
     return dao.baseInsertSelective( entity);
}

/**
* 删除（根据主键ID删除）
* @param id 主键
* @return int
*/
public Integer baseDeleteByPrimaryKey(String id){
     return dao.baseDeleteByPrimaryKey( id);
}

/**
* 删除（根据ID 批量删除）
* @param idList 主键ID列表
* @return int
*/
public Integer baseDeleteBathPrimaryKeys(List<String> idList){
     return dao.baseDeleteBathPrimaryKeys( idList );
}

/**
* 分页查询
* @param entity 实体
* @return Page<WmsCustomerFileConsignee>
*/
@BaseServiceDescribe(moduleName = "客户档案收货人详细信息管理",btnName = "查询客户档案收货人详细信息列表")
public Page<WmsCustomerFileConsignee> baseSelectPage(WmsCustomerFileConsignee entity )throws Exception {
    try {
        PageHelper.startPage(entity.getPage(),entity.getRows());
        return (Page<WmsCustomerFileConsignee>)dao.baseSelectPage( entity );
    } catch (Exception e) {
        throw new ServiceException("查询客户档案收货人详细信息列表",e);
    }
}

/**
* 查询（根据主键ID查询）
* @param id 主键ID
* @return WmsCustomerFileConsignee
*/
@BaseServiceDescribe(moduleName = "客户档案收货人详细信息管理",btnName = "查询唯一客户档案收货人详细信息")
public WmsCustomerFileConsignee baseSelectByPrimaryKey(String id )throws Exception {
    try {
        return dao.baseSelectByPrimaryKey( id );
    } catch (Exception e) {
        throw new ServiceException("查询唯一客户档案收货人详细信息",e);
    }
}

/**
* 查询（根据ID 批量查询）
* @param idList 主键ID列表
* @return list
*/
public Integer baseSelectBathPrimaryKeys(List<WmsCustomerFileConsignee> idList ){
     return dao.baseSelectBathPrimaryKeys( idList );
}

/**
*修改 （匹配有值的字段）
* @param entity 主键ID列表
* @return int
*/
@BaseServiceDescribe(moduleName = "客户档案收货人详细信息",btnName = "修改客户档案收货人详细信息")
public Integer baseUpdateByPrimaryKeySelective(WmsCustomerFileConsignee entity)throws SucessException,ServiceException {
   Integer updateCount = dao.baseUpdateByPrimaryKeySelective( entity);
   if(updateCount>0){
       throw new SucessException("修改客户档案收货人详细信息成功");
   }else{
       throw new ServiceException("修改客户档案收货人详细信息失败，未插入数据库");
   }
}

    /**
     *设为默认
     * @param entity 主键ID列表
     * @return int
     */
    @BaseServiceDescribe(moduleName = "客户档案设为默认",btnName = "设为默认")
    public Integer acquiesceIn(WmsCustomerFileConsignee entity)throws SucessException,ServiceException {
        List<WmsCustomerFileConsignee> list = dao.baseSelectBySskhidAndSfmr(entity.getSskhid());
        if(list.size()>0){
            WmsCustomerFileConsignee wmsCustomerFileConsignee = list.get(0);
            wmsCustomerFileConsignee.setSfmr("0");
            dao.baseUpdateByPrimaryKeySelective(wmsCustomerFileConsignee);
        }
        Integer updateCount = dao.baseUpdateByPrimaryKeySelective( entity);
        if(updateCount>0){
            throw new SucessException("客户档案设为默认成功");
        }else{
            throw new ServiceException("客户档案设为默认失败，未插入数据库");
        }
    }



/**
*修改（根据主键ID修改）
* @param entity 主键ID列表
* @return int
*/
public Integer baseUpdateByPrimaryKey(WmsCustomerFileConsignee entity){
     return dao.baseUpdateByPrimaryKey( entity);
}
}
